import type { IBestCombResult, ISettings } from './types'

/**
 * 对比新旧值
 * @param result 新对比值
 * @param old 旧对比值
 * @param condition 条件参数
 * @returns 返回对比值
 */
export function getBestCombResult(
  result: IBestCombResult,
  old: IBestCombResult,
  settings: ISettings,
) {
  const { sortRule, operatingTime } = settings

  //如果超出运营时间，或者当前组合的收益不如已知的最佳收益，则不更新
  if (result.workingTime > operatingTime) {
    return old
  }

  if (!old.combination.length) {
    return result
  }

  if (sortRule === 'MAX_REVENUE') {
    if (result.totalRevenue > old.totalRevenue) {
      return result
    }
  } else if (sortRule === 'MIN_TIME') {
    if (result.workingTime < old.workingTime) {
      return result
    }
  }

  return old
}
